package cn.sccl.springmvc.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author 饶爽
 * @time 2019年10月27日 下午10:52:24
 * @version 1.0.0
 * 异常处理器的自定义的实现类
*/
public class CustomExceptionResolver implements HandlerExceptionResolver {

    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response,
            Object object, Exception e) {
        //Auto-generated method stub  发生异常的地方 Serivce层  方法  包名+类名+方法名（形参） 字符串
        //日志    1.发布 tomcat war  Eclipse  2.发布Tomcat  服务器上  Linux  Log4j
        ModelAndView view = new ModelAndView();
        if (e instanceof MessageException) {
            MessageException me = (MessageException) e;
            view.addObject("error", me.getMsg());
        }else {
            view.addObject("error", "未定义异常！");
        }
        view.setViewName("error");
        return view;
    }

}
